﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using DataAccess;

namespace BusinessLayer
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "FaultService" in code, svc and config file together.
    public class FaultService : IFaultService
    {
        public string GenerateNumber()
        {
            string Ticket = "";

            for (int i = 0; i < 6; i++)
            {
                Random r = new Random();
                Ticket += r.Next(0, 10).ToString();
            }

            return Ticket;
        }

        public bool FaultLogin(string username,string Token, string pin)
        {
            Encryption enc = new Encryption();
            string pass = enc.DecryptTripleDES(Token, pin);

            bool found = new UserRepository().UserLogin(username, pass);

            if (found == true)
                return true;
            else
                return false;
        }

        public void FileFaultReport(string username, int ProductID,string details)
        {
            new FaultRepository().AddFaultDetails(username, ProductID,details);
        }

        public IEnumerable<Common.UserProductFault> ListOfItemFaults(int ProductID, DateTime startdate, DateTime endDate, string username)
        {
            return new FaultRepository().ListOfItemFaults(ProductID, startdate, endDate, username);
        }


        public IEnumerable<Common.UserProductFault> getAllFaults()
        {
            return new FaultRepository().getAllFaults();
        }

        public Common.UserProductFault getFaultByID(int id)
        {
            return new FaultRepository().getFaultByID(id); 
        }

        public Common.UserProductFault getFaultByIDOrderID(int id, Guid orderID)
        {
            return new FaultRepository().getFaultByID(id, orderID);
        }

        public IEnumerable<Common.Fault> GetAllFaultStatus()
        {
            return new FaultRepository().GetAllFaultStatus();
        }

        public Common.Fault getFaultStatusByID(int id)
        {
            return new FaultRepository().getFaultStatusByID(id);
        }

        public void addFaultLog(Common.FaultLog fault)
        {
            new FaultRepository().addFaultLog(fault);
        }

        public void UpdateFault(Common.UserProductFault fault)
        {
            new FaultRepository().UpdateFault(fault);
        }

        public string CreatePDFFault(Common.UserProductFault fault)
        {
            return new FaultRepository().CreatePDFFault(fault);
        }
    }
}
